package org.xcorpio.thread;

class RunnableThread implements Runnable {

	private int ticket = 10;

	@Override
	public void run() {
		synchronized (this) {
			for (int i = 0; i < 20; i++) {
				if (ticket > 0) {
					//ticket = ticket - 1;
					System.out.println(Thread.currentThread().getName()
							+ " 卖票：ticket" + ticket--);
				}
			}
		}
		
	}

}

public class RunnableTest {
	public static void main(String[] args) {
		RunnableThread runnableThread = new RunnableThread();
		Thread thread1 = new Thread(runnableThread);
		Thread thread2 = new Thread(runnableThread);
		Thread thread3 = new Thread(runnableThread);
		thread1.start();
		thread2.start();
		thread3.start();
	}
}